package com.bnz.consumer.listener;

import com.alibaba.fastjson.JSON;
import com.bnz.common.utils.SendJmsUtil;
import com.bnz.consumer.config.SmsProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@RabbitListener(queues = "code")
public class UserConsumerListener {
    @Autowired
    private SmsProperties smsProperties;
    // 1. 得到由rabbitmq发送的信息，并将信息发送给阿里云
    public void getCode(Map<String,String> map){
        //1.1 得到手机号码
        String phone = map.get("phone");
        System.out.println("phone = " + phone);
        // 1.2 得到验证码
        String code = map.get("code");
        System.out.println("code = " + code);
        // 1.3 定义一个map，将code放到map中
        Map<String,String> m = new HashMap<>();
        m.put("code",code);
        // 1.4 开始发送短信验证码给阿里云
        SendJmsUtil.sendCode(smsProperties.getAccessKeyId(),
                             smsProperties.getAccessKeySecret(),
                             smsProperties.getSignName(),
                             smsProperties.getTemplateCode(),
                             phone,
                             JSON.toJSONString(m));
    }
}
